<script setup lang="ts">
import { onMounted } from 'vue'
import { useMenuStore } from '@/stores/modules/menu'
import { useRouter } from 'vue-router'
import axios from 'axios'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { isMobile } from '@/utils'
const locale = zhCn

const menuStore = useMenuStore()
const router = useRouter()
const roleId = localStorage.getItem('ROLE_ID')
roleId &&
	menuStore.saveMenuList(Number(roleId)).then(() => {
		// 登录成功进入主界面
		router.replace(location.pathname)
		// console.log('location.pathname ',location.pathname)
		router.replace('/')
	})

// 封装
const getUserIp = () => {
	let url = 'https://api.ipify.org?format=json'
	return axios.get(url).then(res => res.data.ip)
}

// 获取
const funX = async () => {
	let ip = await getUserIp()
	console.log(ip) // 获取用户公网 ip 地址
	localStorage.setItem('IP', ip)
}

window.addEventListener('resize',()=>{
    // 示例： 全局变量
	// app.config.globalProperties.device = isMobile()
    //  import { getCurrentInstance } from 'vue'
	// const { appContext } = getCurrentInstance()
	// appContext.config.globalProperties.device
	menuStore.setDevice(!isMobile())
})

onMounted(() => {
	funX()
})
</script>

<template>
	<el-config-provider :locale="locale">
		<router-view />
	</el-config-provider>
</template>

<style>
#nprogress .bar {
	background: rgb(13, 0, 255) !important;
}
#nprogress .peg {
	box-shadow: 0 0 10px red, 0 0 5px red !important;
}
</style>
